/*#####################################
 Corso di visione artificiale
 Elaborazione di immagini in C/C++
 main function
 main.cpp
 #####################################*/

#include <iostream>
#include "functionsPgm.h"
#include "pnm_utils.h"
using namespace std;
int main(int argc, char* argv[]) {
	
    //if(argc < 2){
    //  printf("[EE] Usage: %s file.pgm \n",argv[0]);
    //  return EXIT_FAILURE;
    //}d
	
    //char* filename = argv[1];
	
    /// attenzione! controlla estensione immagine e funzioni load write
	
    //dimensioni immagine
    unsigned int width;
    unsigned int height;
    unsigned int rayFilter=1; //quindi 3x3
    unsigned int treshold = 200;
    unsigned int middleTreshold = 128;
    //Declare Images buffer
    unsigned char * input_buffer = pgm_load(width, height, "lena.pgm");
    unsigned char * output_buffer = new unsigned char[width*height];
	
	
    // operazioni sull'immagine ...
	
    //sogliatura
    sogliatura( input_buffer,output_buffer,width,height,treshold);
    write_pgm("sogliatura200.pgm", output_buffer, width, height);
	
    //binarizzazione
    sogliatura( input_buffer,output_buffer,width,height,middleTreshold);
    write_pgm("binarizzazione.pgm", output_buffer, width, height);
	
	//istogramma
    istogramma(input_buffer,width,height);
    
	//abbassamento luminosità
    treshold = 50;
    abbLum(input_buffer,output_buffer,width,height,treshold);
    write_pgm("abbLuminosità.pgm", output_buffer, width, height);
    
	//filtro mediano
    filtroMed(input_buffer,output_buffer,width,height,rayFilter);
    write_pgm("mediano.pgm", output_buffer, width, height);
    
	//sottrazione
    unsigned char * input_buffer2 = pgm_load(width, height, "input_image.pgm");
    input_buffer = pgm_load(width, height, "background_image.pgm");
    subImg(input_buffer,input_buffer2,output_buffer,width,height);
    write_pgm("sottrazione.pgm", output_buffer, width, height);
	
	
	
	
    //delete
    delete[]input_buffer;
    delete[]output_buffer;
	
    return 0;
}
